<?php require_once("autoload2.php"); ?>
<?php require_once("config.php"); ?>
<?php

$languages = new languages();
$list_languages = $languages->list_languages();

if (isset($_SESSION['loginsession'])) redirect("/pages/menu.php");


$error = false;
if (isset($_POST['username'])) {
    $userwebObj = new webusers();

    $returnLogin = $userwebObj->login($_POST['username'], $_POST['password']);

    if ($returnLogin) {
        $_SESSION['emailsession'] = $_POST['username'];
        $_SESSION['loginsession'] = $returnLogin;
        $_SESSION['languagesession'] = $_POST['language'];
        redirect("/pages/menu.php");
        
    } else {
        $error = true;
    }
}


?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>FO Salon | Login</title>
    <link rel="stylesheet" href="css/style.css" type="text/css"/>
    <script type="text/javascript" src="js/plugins/jquery-1.7.min.js"></script>
    <script type="text/javascript" src="js/plugins/jquery-ui-1.8.16.custom.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('.loginform button').hover(function () {
                $(this).stop().switchClass('default', 'hover');
            }, function () {
                $(this).stop().switchClass('hover', 'default');
            });

            <?php if (isset($_GET['action']) && $_GET['action']=="logout") {?>
            jQuery('.logoutmsg').slideDown();
            <?php }?>

            <?php if ($error) {?>
            var u = jQuery(this).find('#username');
            if (u.val() == '') {
                jQuery('.loginerror').slideDown();
                u.focus();
            }
            <?php }?>

            $('#username').keypress(function () {
                jQuery('.loginerror').slideUp();
            });
        });
    </script>
    <!--[if lt IE 9]>
    <script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script>
    <![endif]-->
</head>

<body class="login">

<div class="loginbox radius3">
    <div class="loginboxinner radius3">
        <div class="loginheader">
            <h1 class="bebas">Entrar</h1>

            <div class="logo"><img src="images/starlight_admin_template_logo.png" alt=""/></div>
        </div>
        <!--loginheader-->

        <div class="loginform">
            <div class="loginerror"><p>Invalid username or password</p></div>
            <div class="logoutmsg"><p>Closed session</p></div>
            <form id="login" action="index.php" method="post">
                 <p>
                            <label for="language" class="bebas">Language</label>
                            <span class="field">
                            <select name="language">
                                <option value="0">[Choose language]</option>
                                <?php foreach ($list_languages as $item) { ?>
                                    <option value="<?php echo $item->id; ?>">
                                            <?php echo $item->name; ?>
                                    </option>
                                <?php } ?>
                            </select>
                            </span>
                </p>

                <p>
                    <label for="username" class="bebas">USER</label>
                    <input type="text" id="username" name="username" class="radius2"/>
                </p>

                <p>
                    <label for="password" class="bebas">PASSWORD</label>
                    <input type="password" id="password" name="password" class="radius2"/>
                </p>

                <p>
                    <button class="radius3 bebas">SIGN IN</button>
                </p>
                <p><a href="" class="whitelink small">Can't access your account?</a></p>
            </form>
        </div>
        <!--loginform-->
    </div>
    <!--loginboxinner-->
</div>
<!--loginbox-->

</body>
</html>

